﻿using Anke.SHManage.BLL;
using Anke.SHManage.MSSQLDAL;
using Anke.SHManage.Web.Reports.DataSetForPrintTableAdapters;
using Microsoft.Reporting.WebForms;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Anke.SHManage.Web.Reports
{
    public partial class PrintModeWebForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Data_Binding();
            }
        }

        private void Data_Binding()
        {
            string strReportName = Server.UrlDecode(Request.QueryString["AlarmEventType"]); //System.Web.HttpContext.Current.Session["ReportName"].ToString();
            string taskCode = Request.QueryString["TaskCode"];
            int patientOrder = Convert.ToInt32(Request.QueryString["PatientOrder"]);
            string IsSeePeople = Server.UrlDecode(Request.QueryString["IsSeePeople"]); //空车是否 见到病人 add2024-07-15 plq
            //ifCharge为 0 ，一般病历单打印，ifCharge为1 ，病历收费打印
            //int ifCharge = Convert.ToInt32(Request.QueryString["IfCharge"]);

            string submitLogo = Request.QueryString["SubmitLogo"];//20151214提交标志
            if (submitLogo == "true" || submitLogo == null)
            {
                ReportViewer1.ShowToolBar = true;//显示功能列表
            }
            else
                ReportViewer1.ShowToolBar = false;//隐藏功能列表

            //string IFHasPower = "无";
            //List<int> roles = UserOperateContext.Current.Session_UsrRole; //获取登录人角色
            //string configRole = System.Configuration.ConfigurationManager.AppSettings["PRAuditCPR"]; //配置文件中取出能有审核心肺复苏的角色编码
            //string[] tcr = configRole.Split(',');

            //M_PatientChargeDAL dalzz = new M_PatientChargeDAL();
            //DataTable dtroscif = dalzz.getPatientROSCPrint(taskCode, patientOrder);//通过ROSC的车到前CPR的长度判断是否填写了ROSC
            //string tempcpr = dtroscif.Rows[0][3].ToString();
            //foreach (string i in tcr)
            //{
            //    int changeI = Convert.ToInt32(i);

            //    if (roles.Contains(changeI) && tempcpr.Length > 0) { IFHasPower = "有"; } //判断只有当角色有查看ROSC权限，并且ROSC有填写，同时满足才可以查看
            //}

            //if (ifCharge == 0)
            //{
                switch (strReportName)
                {
                    case "救治":
                        Print_PatientRecord_JijiuTableAdapter ada = new Print_PatientRecord_JijiuTableAdapter();
                        DataSetForPrint.Print_PatientRecord_JijiuDataTable dt = ada.GetData(taskCode, patientOrder);
                        ReportDataSource rdsjz = new ReportDataSource("DataSet1", dt.AsEnumerable());
                        this.ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Reports/PrintPatient.rdlc");
                        this.ReportViewer1.LocalReport.DataSources.Add(rdsjz);

                        break;
                    case "一般转院":
                    case "急救转院":
                        Print_PatientRecord_ZhuanYuanTableAdapter adazhuanyuan = new Print_PatientRecord_ZhuanYuanTableAdapter();
                        DataSetForPrint.Print_PatientRecord_ZhuanYuanDataTable dtzhuanyuan = adazhuanyuan.GetData(taskCode, patientOrder);
                        ReportDataSource rdszy = new ReportDataSource("DataSetForZhuanYuan", dtzhuanyuan.AsEnumerable());
                        this.ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Reports/PrintPatientZhuanYun.rdlc");
                        this.ReportViewer1.LocalReport.DataSources.Add(rdszy);
                        break;

                    case "回家":
                        Print_PatientRecord_ChuyuanTableAdapter adachuyuan = new Print_PatientRecord_ChuyuanTableAdapter();
                        DataSetForPrint.Print_PatientRecord_ChuyuanDataTable dtchuyuan = adachuyuan.GetData(taskCode, patientOrder);
                        ReportDataSource rdshj = new ReportDataSource("DataSetChuyuan", dtchuyuan.AsEnumerable());
                        this.ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Reports/PrintPatientChuYuan.rdlc");
                        this.ReportViewer1.LocalReport.DataSources.Add(rdshj);
                        break;

                    case "空车":
                        if (IsSeePeople == "见人") //空车--见到病人，该类型病历打印需要按照救治病历模板打印 add2024-07-15 plq
                        {
                            Print_PatientRecord_JijiuTableAdapter adakongche_jr = new Print_PatientRecord_JijiuTableAdapter();
                            DataSetForPrint.Print_PatientRecord_JijiuDataTable dtkongche_jr = adakongche_jr.GetData(taskCode, patientOrder);
                            ReportDataSource rdskc_jr = new ReportDataSource("DataSet1", dtkongche_jr.AsEnumerable());
                            this.ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Reports/PrintPatient.rdlc");
                            this.ReportViewer1.LocalReport.DataSources.Add(rdskc_jr);

                            break;
                        }
                        else
                        {
                            Print_PatientRecord_KongCheTableAdapter adakongche = new Print_PatientRecord_KongCheTableAdapter();
                            DataSetForPrint.Print_PatientRecord_KongCheDataTable dtkongche = adakongche.GetData(taskCode, patientOrder);
                            ReportDataSource rdskc = new ReportDataSource("DataSetKongChe", dtkongche.AsEnumerable());
                            this.ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Reports/PrintPatientKongChe.rdlc");
                            this.ReportViewer1.LocalReport.DataSources.Add(rdskc);
                            break;
                        }
                    case "其他"://将“取暖箱”改为“其他” 2016-12-12 周志猛
                        Print_PatientRecord_KongCheTableAdapter adaqunuanxiang = new Print_PatientRecord_KongCheTableAdapter();
                        DataSetForPrint.Print_PatientRecord_KongCheDataTable dtqunuanxiang = adaqunuanxiang.GetData(taskCode, patientOrder);
                        ReportDataSource rdsqnx = new ReportDataSource("DataSetForQuNuanXiang", dtqunuanxiang.AsEnumerable());
                        this.ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Reports/PrintPatientQuNuanXiang.rdlc");
                        this.ReportViewer1.LocalReport.DataSources.Add(rdsqnx);
                        break;


                    default:
                        break;
                }

                this.ReportViewer1.LocalReport.Refresh();
            //}
            //else
            //{
            //    switch (strReportName)
            //    {
            //        case "救治":
            //            this.ReportViewer1.LocalReport.DataSources.Clear();
            //            this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(@"~/Reports/PatientChargePrintForJiJiuOrZhuanyuan.rdlc");
            //            Microsoft.Reporting.WebForms.ReportParameter ed = new Microsoft.Reporting.WebForms.ReportParameter("IFHasPower", IFHasPower);//传参判断是否有查看权限
            //            this.ReportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { ed });
            //            M_PatientChargeDAL dal = new M_PatientChargeDAL();
            //            DataTable dtrosc1 = dal.getPatientROSCPrint(taskCode, patientOrder);//新增ROSC的打印
            //            this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForPatientROSC", dtrosc1));
            //            DataTable dt = dal.getPatientChargePrintCar(taskCode, patientOrder);
            //            this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForCPCar", dt));
            //            DataTable dt1 = dal.getPatientChargePrintOther(taskCode, patientOrder);
            //            this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForCPOther", dt1));
            //            break;
            //        case "一般转院":
            //        case "急救转院":
            //            this.ReportViewer1.LocalReport.DataSources.Clear();
            //            this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(@"~/Reports/PatientChargePrintForJiJiuOrZhuanyuan.rdlc");
            //            Microsoft.Reporting.WebForms.ReportParameter ed1 = new Microsoft.Reporting.WebForms.ReportParameter("IFHasPower", IFHasPower);
            //            this.ReportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { ed1 });
            //            M_PatientChargeDAL dal1 = new M_PatientChargeDAL();
            //            DataTable dtrosc2 = dal1.getPatientROSCPrint(taskCode, patientOrder);//新增ROSC的打印
            //            this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForPatientROSC", dtrosc2));
            //            DataTable dt2 = dal1.getPatientChargePrintCar(taskCode, patientOrder);
            //            this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForCPCar", dt2));
            //            DataTable dt3 = dal1.getPatientChargePrintOther(taskCode, patientOrder);
            //            this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForCPOther", dt3));
            //            break;

            //        case "回家":
            //            this.ReportViewer1.LocalReport.DataSources.Clear();
            //            this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(@"~/Reports/PatientChargePrintForHuiJia.rdlc");
            //            Microsoft.Reporting.WebForms.ReportParameter ed2 = new Microsoft.Reporting.WebForms.ReportParameter("IFHasPower", IFHasPower);
            //            this.ReportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { ed2 });
            //            M_PatientChargeDAL dal2 = new M_PatientChargeDAL();
            //            DataTable dtrosc3 = dal2.getPatientROSCPrint(taskCode, patientOrder);//新增ROSC的打印
            //            this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForPatientROSC", dtrosc3));
            //            DataTable dt4 = dal2.getPatientChargePrintCar(taskCode, patientOrder);
            //            this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForHJCar", dt4));
            //            DataTable dt5 = dal2.getPatientChargePrintZhiLiao(taskCode, patientOrder);
            //            this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForHJZhiLiao", dt5));
            //            break;

                   
            //        case "取暖箱":
            //            this.ReportViewer1.LocalReport.DataSources.Clear();
            //            this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(@"~/Reports/PatientChargePrintForQuNuanXiang.rdlc");
            //            M_PatientChargeDAL dal3 = new M_PatientChargeDAL();
            //            DataTable dt6 = dal3.getPatientChargePrintCar(taskCode, patientOrder);
            //            this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForChargePrintKongChe", dt6));
            //            break;

            //        case "空车":
            //            this.ReportViewer1.LocalReport.DataSources.Clear();
            //            this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(@"~/Reports/PatientChargePrintForKongChe.rdlc");
            //            M_PatientChargeDAL dal4 = new M_PatientChargeDAL();
            //            DataTable dt7 = dal4.getPatientChargePrintCar(taskCode, patientOrder);
            //            this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForChargePrintKongChe1", dt7));
            //            break;
            //        default:
            //            break;
            //    }
            //    this.ReportViewer1.LocalReport.Refresh();
            //}
        }
    }
}